package com.air.ota.util;

import org.apache.commons.codec.binary.Hex;

public class PkgUtil {
	
	
	static private int  pkgSequence;
	
	synchronized public static void setCurrentPkgSequence(byte[] currentSequence){
		if (Integer.parseInt(HexStringUtil.bytesToHexString(currentSequence),16)<=pkgSequence){
			return;
		}
		pkgSequence = Integer.parseInt(HexStringUtil.bytesToHexString(currentSequence),16);
	}
	
	public static byte[] getNextPkgSequence(){
		
		++pkgSequence;
		String hexString=Integer.toHexString(pkgSequence);
		int fillCount = 8-hexString.length();
		
		for(int i=0;i<fillCount;i++){
			hexString = "0"+hexString;
		}
		
		return HexStringUtil.hexStringToBytes(hexString);
		//return ++pkgSequence;
	}
}
